import cryptoJs from "../utils/encryptDES.js";
import {
	apiMixUrlKeyApi
} from "../api/assemb.js"
import {
	dologin
} from "./login.js"

function requestkey() {
	uni.getProvider({
		service: 'oauth',
		success: function(res) {
			console.log(res.provider)
			if (~res.provider.indexOf('weixin')) {
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						let param = {
							code: loginRes.code
						}
						apiMixUrlKeyApi(param, 1065, 'ParseWxCode').then((res) => {
							var str = res.data.replace(/[\r\n]/g, "");
							var key = loginRes.code.substring(0, 8);
							const content = cryptoJs.decrypt2(str, key);
							uni.setStorage({
								key: "key",
								data: content,
							});
							// 登录
							dologin()
						})
					}
				});
			}
		}
	});
}

export {
	requestkey
};